class Solution
{
public:
    vector<int> closestPrimes(int left, int right)
    {
        vector<bool> isPrime(right + 1, true);
        isPrime[0] = isPrime[1] = false;
        for (long long i = 2; i <= right; ++i)
        {
            if (isPrime[i])
            {
                for (long long j = i * i; j <= right; j += i)
                {
                    isPrime[j] = false;
                }
            }
        }

        int lastPrime = -1;
        for (int i = left; i <= right; ++i)
        {
            if (isPrime[i])
            {
                lastPrime = i;
                break;
            }
        }
        if (lastPrime == -1)
        {
            return {-1, -1};
        }

        int minDistance = INT_MAX;
        vector<int> resultPair = {-1, -1};
        for (int i = lastPrime + 1; i <= right; ++i)
        {
            if (isPrime[i])
            {
                int distance = i - lastPrime;
                if (distance < minDistance)
                {
                    minDistance = distance;
                    resultPair = {lastPrime, i};
                }
                lastPrime = i;
            }
        }
        return resultPair;
    }
};